from django.db import models
from django.conf import settings
from django.contrib.postgres.fields import ArrayField
from django.utils.translation import ugettext_lazy as _

from ..projects.utils.choices import IMAGE_TYPE
from .services import get_train_model_path


class NetworkModel(models.Model):
    """
    网络模型
    """
    name = models.CharField(max_length=250, null=False, blank=True, verbose_name=_("name"))
    "描述"
    description = models.TextField(null=False, blank=True, verbose_name=_("description"))

    class Meta:
        verbose_name = "网络模型"
        verbose_name_plural = "网络模型"

    def __str__(self):
        return self.name


class ModelInfo(models.Model):
    """
    模型信息
    """
    name = models.CharField(max_length=128, null=False, blank=True, verbose_name=_("name"))
    "迭代次数"
    iterations_number = models.PositiveIntegerField(verbose_name=_("iteration number"))
    "图片类型"
    image_type = models.CharField(max_length=16, choices=IMAGE_TYPE, default="0", verbose_name=_("image type"))
    "类别数"
    category_number = models.PositiveIntegerField(verbose_name=_("category_number"))
    "类别信息"
    category_info = ArrayField(models.TextField(null=False, blank=False),
                               null=True, blank=True, default=list, verbose_name=_("category info"))
    "网络模型"
    network_model = models.ForeignKey(NetworkModel, blank=False, null=True, on_delete=models.CASCADE,
                                      verbose_name=_("network model"))
    "模型路径"
    models_path = models.FileField(upload_to=get_train_model_path, max_length=500, null=True, blank=True,
                                   verbose_name=_("model"))
    "训练数据"
    train_data = models.ForeignKey("datas.MarkData", blank=False, null=True, default=True, on_delete=models.CASCADE,
                                   verbose_name=_("train data"))
    "创建日期"
    created_date = models.DateTimeField(verbose_name=_("created date"), auto_now_add=True)
    "训练人员"
    train_user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=False, null=True, default=True,
                                   on_delete=models.CASCADE,
                                   verbose_name=_("train user"))
    "描述"
    description = models.TextField(null=True, blank=False, verbose_name=_("description"))

    class Meta:
        verbose_name = "模型信息"
        verbose_name_plural = "模型信息"

    def __str__(self):
        return self.name
